package com.lcl.jarvis.controller;

import com.lcl.jarvis.dto.DoctorsDTO;
import com.lcl.jarvis.dto.DoctorsQueryDTO;
import com.lcl.jarvis.service.DoctorsService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import com.lcl.jarvis.util.Result;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author licl
 * @since 2024-05-16
 */
@RestController
@Slf4j
@Api(value = "/web/business/doctors", tags = {"医生信息模块操作"})
@RequestMapping("/web/business/doctors")
public class DoctorsController {


    private final DoctorsService doctorsService;

    @Autowired
    public DoctorsController(DoctorsService doctorsService){
        this.doctorsService = doctorsService;
    }
    /**
     * 通过ID查询
     *
     * @param id ID
     * @return Doctors
     */
    @ApiOperation(value = "通过ID查询", tags = {"通过ID查询"}, notes = "ID不能为空")
    @GetMapping("/{id}")
    public Result<DoctorsDTO> get(@PathVariable String id) {
        return Result.ok(doctorsService.queryById(id));
    }

    /**
     * 分页查询信息
     *
     * @param doctorsQuery 分页对象
     * @return 分页对象
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "doctors", value = "查询条件", dataType = "DoctorsQueryDTO", paramType = "query")
    })
    public Result<Map<String, Object>> page(DoctorsQueryDTO doctorsQuery) {
        Map<String, Object> map = doctorsService.queryPage(doctorsQuery);
    	// 如不想动BO，此处可以再加工为前台需要的自定义对象，适配界面用，例如 (**DTO)map.get("result")
    	return Result.ok(map);
    }

    /**
     * 添加
     *
     * @param doctors 实体
     * @return success/false
     */
    @PostMapping
    @ApiOperation(value = "添加")
    @ResponseStatus(HttpStatus.CREATED)
    public Result<?> add(@Valid @RequestBody @ApiParam(name="",value="传入json格式",required=true) DoctorsDTO doctorsDto) {
        DoctorsDTO DoctorsDto = doctorsService.save(doctorsDto);
        return Result.ok(DoctorsDto);
    }

    /**
     * 删除
     *
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public Result<?>  delete(@PathVariable String id) {
        doctorsService.delete(id);
        return Result.ok("");
    }

    /**
     * 编辑
     *
     * @param doctors 实体
     * @return success/false
     */
    @PutMapping
    @ApiOperation(value = "编辑")
    @ResponseStatus(HttpStatus.ACCEPTED)
    public Result<?> edit(@Valid @RequestBody @ApiParam(name="",value="传入json格式",required=true) DoctorsDTO doctorsDto) {
        DoctorsDTO DoctorsDto = doctorsService.update(doctorsDto);
        return Result.ok(DoctorsDto);
    }
}
